package chpt10;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

public class BorderLayoutTest {
    public static void main(String[] args) {
        JFrame frame = new JFrame("BorderLayoutTest");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);

        JLabel label = new JLabel("北部标签");
        // 设置标签居中对齐
        label.setHorizontalAlignment(SwingConstants.CENTER); 
        JTextArea textArea = new JTextArea();
        textArea.setText("中部文本域");

        JButton button1 = new JButton("南部按钮1");
        JButton button2 = new JButton("南部按钮2");

        // 创建放到南部区域的面板
        JPanel southPanel = new JPanel();
        southPanel.add(button1);
        southPanel.add(button2);

        // 设置frame的布局管理器为边界布局
        frame.setLayout(new BorderLayout());

        // 添加组件到窗体的不同区域
        frame.add(label, BorderLayout.NORTH);
        frame.add(textArea, BorderLayout.CENTER);
        frame.add(southPanel, BorderLayout.SOUTH);

        frame.setVisible(true);
    }
}